<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>trim()函数</title>
</head>
<body>
    <script>
        //trim()函数:去除两端的空格和转义字符
        //去除不了字符串中间的空格和转义字符
        var str1 = "  \t  hello world!   \n   ";
        document.write(str1.trim(),"<br>");
        
        //ES6拓展:trimStart():消除·字符串前面的空格或者转义字符
        //ES6拓展:trimEnd():消除·字符串后面的空格或者转义字符
        var str2 = "    hello world!      ";
        document.write(str2.trimStart(),"<br>");//hello world!      <br>
        document.write(str2.trimEnd(),"<br>");//    hello world!
    </script>
</body>
</html>